package com.v1.video.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.v1.video.Constant;
import com.v1.video.R;
import com.v1.video.db.dao.VideoTB;
import com.v1.video.domain.LoginInfo;
import com.v1.video.domain.RecommendAdEntity.RecommendAdInfo;
import com.v1.video.domain.RecommendEntity.CategoryInfo;
import com.v1.video.engine.NetEngine;
import com.v1.video.interfaces.OnChannelListener;
import com.v1.video.util.Helper;
import com.v1.video.util.TransferUtils;
import com.v1.video.util.Utility;
import com.v1.video.util.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 推荐频道适配器
 * 
 * @author wangfang
 * 
 */
public class RecommendAdapter2 extends BaseAdapter {

	private LayoutInflater mLayoutInflater;
	private Context mContext;
	private List<CategoryInfo> mLstData;
	private List<List<RecommendAdInfo>> mAdLstData;
	private int mHeight;
	private int mAdHeight;
	private int mWidth;
	private int mAdWidth;
	private OnChannelListener mOnChannelListener;

	public RecommendAdapter2(Context context) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mLstData = new ArrayList<CategoryInfo>();
//		int screenWidth = WindowUtils.getScreenWidth(mContext);
//		float dpi = WindowUtils.getDensity(mContext);
//		mWidth = (int) ((screenWidth - dpi * 24) / 2);
		float padding = mContext.getResources().getDimension(
				R.dimen.margin_size_13) * 2;
		float margin = mContext.getResources().getDimension(
				R.dimen.margin_size_4);
		mWidth = Utils.computeImageWidth(mContext, (int) (padding + margin), 2);
		mAdWidth = Utils.computeImageWidth(mContext, (int) (padding), 1);
//		mHeight = Utils.computeImageHeight(mContext, (int) (padding + margin),
//				2);
		mHeight = mWidth*9/16;
		mAdHeight = (int) (mAdWidth*(0.37));
	}

	public List<CategoryInfo> getLstData() {
		return mLstData;
	}

	public void setLstData(List<CategoryInfo> mLst) {
		if (mLst != null && mLst.size() > 0) {
			this.mLstData = mLst;
			this.notifyDataSetChanged();
		}
	}

	public void setAdLstData(List<List<RecommendAdInfo>> admLst) {
		if (admLst != null && admLst.size() > 0) {
			this.mAdLstData = admLst;
			this.notifyDataSetChanged();
		}
	}

	public void setOnChannelListener(OnChannelListener onChannelListener) {
		mOnChannelListener = onChannelListener;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mLstData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mLstData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.fragment_recommend_item2, null);
			holder = new Holder();
			holder.name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.more = (TextView) convertView.findViewById(R.id.tv_more);
			holder.layLine = convertView.findViewById(R.id.lay_line);
			holder.layLink = convertView.findViewById(R.id.lay_link);
			holder.mark = (TextView) convertView.findViewById(R.id.tv_mark);
			holder.linktitle = (TextView) convertView
					.findViewById(R.id.tv_linktitle);
			holder.layLink2 = convertView.findViewById(R.id.lay_link2);
			holder.mark2 = (TextView) convertView.findViewById(R.id.tv_mark2);
			holder.linktitle2 = (TextView) convertView
					.findViewById(R.id.tv_linktitle2);
			holder.layitem = convertView.findViewById(R.id.lay_item);
			holder.image = (ImageView) convertView.findViewById(R.id.iv_image);
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.subtitle = (TextView) convertView
					.findViewById(R.id.tv_subtitle);
			holder.corner = (TextView) convertView.findViewById(R.id.tv_corner);
			holder.layitem2 = convertView.findViewById(R.id.lay_item2);
			holder.image2 = (ImageView) convertView
					.findViewById(R.id.iv_image2);
			holder.title2 = (TextView) convertView.findViewById(R.id.tv_title2);
			holder.subtitle2 = (TextView) convertView
					.findViewById(R.id.tv_subtitle2);
			holder.corner2 = (TextView) convertView.findViewById(R.id.tv_corner2);
			holder.layRow = convertView.findViewById(R.id.lay_row);
			holder.layitem3 = convertView.findViewById(R.id.lay_item3);
			holder.image3 = (ImageView) convertView
					.findViewById(R.id.iv_image3);
			holder.title3 = (TextView) convertView.findViewById(R.id.tv_title3);
			holder.subtitle3 = (TextView) convertView
					.findViewById(R.id.tv_subtitle3);
			holder.corner3 = (TextView) convertView.findViewById(R.id.tv_corner3);
			holder.layitem4 = convertView.findViewById(R.id.lay_item4);
			holder.image4 = (ImageView) convertView
					.findViewById(R.id.iv_image4);
			holder.title4 = (TextView) convertView.findViewById(R.id.tv_title4);
			holder.subtitle4 = (TextView) convertView
					.findViewById(R.id.tv_subtitle4);
			holder.corner4 = (TextView) convertView.findViewById(R.id.tv_corner4);
			holder.rl_user = (RelativeLayout) convertView.findViewById(R.id.rl_user);
			holder.rl_user2 = (RelativeLayout) convertView.findViewById(R.id.rl_user2);
			holder.rl_user3 = (RelativeLayout) convertView.findViewById(R.id.rl_user3);
			holder.rl_user4 = (RelativeLayout) convertView.findViewById(R.id.rl_user4);

			holder.iv_headpic = (ImageView) convertView.findViewById(R.id.iv_headpic);
			holder.iv_headpic2 = (ImageView) convertView.findViewById(R.id.iv_headpic2);
			holder.iv_headpic3 = (ImageView) convertView.findViewById(R.id.iv_headpic3);
			holder.iv_headpic4 = (ImageView) convertView.findViewById(R.id.iv_headpic4);

			holder.user_name = (TextView) convertView.findViewById(R.id.user_name);
			holder.user_name2 = (TextView) convertView.findViewById(R.id.user_name2);
			holder.user_name3 = (TextView) convertView.findViewById(R.id.user_name3);
			holder.user_name4 = (TextView) convertView.findViewById(R.id.user_name4);

			holder.tv_duration = (TextView) convertView.findViewById(R.id.tv_duration);
			holder.tv_duration2 = (TextView) convertView.findViewById(R.id.tv_duration2);
			holder.tv_duration3 = (TextView) convertView.findViewById(R.id.tv_duration3);
			holder.tv_duration4 = (TextView) convertView.findViewById(R.id.tv_duration4);

			holder.view_ad =  convertView.findViewById(R.id.view_ad);
			holder.ll_ad =  convertView.findViewById(R.id.ll_ad);
			holder.iv_ad = (ImageView) convertView.findViewById(R.id.iv_ad);
			holder.iv_ad1 = (ImageView) convertView.findViewById(R.id.iv_ad1);
			holder.iv_ad2 = (ImageView) convertView.findViewById(R.id.iv_ad2);
			holder.ad_title = (TextView) convertView.findViewById(R.id.ad_title);
			holder.ad_biaoqian = (TextView) convertView.findViewById(R.id.ad_biaoqian);
			holder.view_adline = convertView.findViewById(R.id.view_adline);

			holder.tv_logo = (TextView) convertView.findViewById(R.id.tv_logo);
			holder.tv_logo2 = (TextView) convertView.findViewById(R.id.tv_logo2);
			holder.tv_logo3 = (TextView) convertView.findViewById(R.id.tv_logo3);
			holder.tv_logo4 = (TextView) convertView.findViewById(R.id.tv_logo4);

			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		final CategoryInfo info = mLstData.get(position);
		if (!TextUtils.isEmpty(info.getName())) {
			holder.name.setText(info.getName());
		} else {
			holder.name.setText("");
		}
		if (info.getIsmore() == 0) {
			holder.more.setVisibility(View.GONE);
		} else {
			holder.more.setVisibility(View.VISIBLE);
		}
		if (info.getLittetop() != null && info.getLittetop().size() > 0) {
			holder.layLine.setVisibility(View.VISIBLE);
			holder.layLink.setVisibility(View.VISIBLE);
			holder.layLink2.setVisibility(View.GONE);
			for (int i = 0; i < info.getLittetop().size(); i++) {
				VideoTB littetop = info.getLittetop().get(i);
				switch (i) {
				case 0:
					if (!TextUtils.isEmpty(littetop.getMark())) {
						holder.mark.setText(littetop.getMark());
					} else {
						holder.mark.setText("");
					}
					if (!TextUtils.isEmpty(littetop.getTitle())) {
						holder.linktitle.setText(littetop.getTitle());
					} else {
						holder.linktitle.setText("");
					}
					break;
				case 1:
					holder.layLink2.setVisibility(View.VISIBLE);
					if (!TextUtils.isEmpty(littetop.getMark())) {
						holder.mark2.setText(littetop.getMark());
					} else {
						holder.mark2.setText("");
					}
					if (!TextUtils.isEmpty(littetop.getTitle())) {
						holder.linktitle2.setText(littetop.getTitle());
					} else {
						holder.linktitle2.setText("");
					}
					break;
				default:
					break;
				}
			}
		} else {
			holder.layLine.setVisibility(View.GONE);
			holder.layLink.setVisibility(View.GONE);
			holder.layLink2.setVisibility(View.GONE);
		}
		holder.layitem.setVisibility(View.VISIBLE);
		holder.layitem2.setVisibility(View.VISIBLE);
		
		ViewGroup.LayoutParams param_ad =holder.iv_ad.getLayoutParams();
		param_ad.height = mAdHeight;
//		param_ad.width = mAdWidth;
		
		ViewGroup.LayoutParams params = holder.image.getLayoutParams();
		params.height = mHeight;
//		params.width = mWidth;
		holder.image.setLayoutParams(params);
//		ViewGroup.LayoutParams params2 = holder.image2.getLayoutParams();
//		params2.height = mHeight;
//		params2.width = mWidth;
//		holder.image2.setLayoutParams(params2);
//		ViewGroup.LayoutParams params3 = holder.image3.getLayoutParams();
//		params3.height = mHeight;
//		params3.width = mWidth;
//		holder.image3.setLayoutParams(params3);
//		ViewGroup.LayoutParams params4 = holder.image4.getLayoutParams();
//		params4.height = mHeight;
//		params4.width = mWidth;
//		holder.image4.setLayoutParams(params4);
		if (info.getVideolist() != null && info.getVideolist().size() > 0) {
			holder.image2.setVisibility(View.GONE);
			holder.title2.setVisibility(View.GONE);
			holder.subtitle2.setVisibility(View.GONE);
			holder.corner2.setVisibility(View.GONE);
			holder.layRow.setVisibility(View.GONE);
			holder.layitem3.setVisibility(View.GONE);
			holder.image3.setVisibility(View.GONE);
			holder.title3.setVisibility(View.GONE);
			holder.subtitle3.setVisibility(View.GONE);
			holder.corner3.setVisibility(View.GONE);
			holder.layitem4.setVisibility(View.GONE);
			holder.image4.setVisibility(View.GONE);
			holder.title4.setVisibility(View.GONE);
			holder.subtitle4.setVisibility(View.GONE);
			holder.corner4.setVisibility(View.GONE);

			holder.rl_user.setVisibility(View.GONE);
			holder.iv_headpic.setVisibility(View.GONE);
			holder.user_name.setVisibility(View.GONE);
			holder.tv_duration.setVisibility(View.GONE);

			holder.rl_user2.setVisibility(View.GONE);
			holder.iv_headpic2.setVisibility(View.GONE);
			holder.user_name2.setVisibility(View.GONE);
			holder.tv_duration2.setVisibility(View.GONE);

			holder.rl_user3.setVisibility(View.GONE);
			holder.iv_headpic3.setVisibility(View.GONE);
			holder.user_name3.setVisibility(View.GONE);
			holder.tv_duration3.setVisibility(View.GONE);

			holder.rl_user4.setVisibility(View.GONE);
			holder.iv_headpic4.setVisibility(View.GONE);
			holder.user_name4.setVisibility(View.GONE);
			holder.tv_duration4.setVisibility(View.GONE);

			holder.tv_logo.setVisibility(View.GONE);
			holder.tv_logo2.setVisibility(View.GONE);
			holder.tv_logo3.setVisibility(View.GONE);
			holder.tv_logo4.setVisibility(View.GONE);
			for (int i = 0; i < info.getVideolist().size(); i++) {
				VideoTB video = info.getVideolist().get(i);
				switch (i) {
				case 0:
					holder.image.setVisibility(View.VISIBLE);
					holder.title.setVisibility(View.VISIBLE);
					if (Constant.VIDEO_TYPE_12.equals(video.getAt())
							|| Constant.VIDEO_TYPE_13.equals(video.getAt())
							|| Constant.VIDEO_TYPE_14.equals(video.getAt())
							|| Constant.VIDEO_TYPE_15.equals(video.getAt())) {
						holder.subtitle.setVisibility(View.VISIBLE);
						holder.title.setMaxLines(1);
						if (!TextUtils.isEmpty(video.getSub_title())) {
							holder.subtitle.setText(video.getSub_title());
						} else {
							holder.subtitle.setText("");
						}
					} else {
						holder.subtitle.setVisibility(View.GONE);
						holder.title.setMaxLines(2);
					}
					//<font color="#FF0000">号外</font>！
					if (!TextUtils.isEmpty(video.getTitle())) {
						holder.title.setText(video.getTitle());
						//						holder.title.setText(Html.fromHtml("<font color='#FF0000'>"+"#"+video.getTitle()+"#"+"</font>"+video.getTitle()));
					} else {
						holder.title.setText("");
					}

					if (!TextUtils.isEmpty(video.getMark())) {
						holder.corner.setText(video.getMark());
						holder.corner.setVisibility(View.VISIBLE);
					} else {
						holder.corner.setVisibility(View.GONE);
					}
					if (!TextUtils.isEmpty(video.getPic())) {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image,
								Constant.VIDEO_9_16_OPTION_2);
					} else {
						holder.image
						.setImageResource(R.drawable.common_place_holder_bg_16_10);
					}

					if(!TextUtils.isEmpty(video.getAt()) && video.getAt().equals("11")){
						holder.tv_logo.setVisibility(View.VISIBLE);
						holder.tv_logo.setText("秒评");
					}else{
						holder.tv_logo.setVisibility(View.GONE);
					}

					if(video.getAt().equals("5") || video.getAt().equals("11")){
						holder.rl_user.setVisibility(View.GONE);
					}else{
						holder.rl_user.setVisibility(View.VISIBLE);
						holder.iv_headpic.setVisibility(View.VISIBLE);
						holder.user_name.setVisibility(View.VISIBLE);
						holder.tv_duration.setVisibility(View.VISIBLE);

						ImageLoader.getInstance().displayImage(video.getHeadpic(),
								holder.iv_headpic, Constant.IMAGE_OPTIONS_FOR_USER_OTHER, new SimpleImageLoadingListener() {

							public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
								if(loadedImage!=null){
									ImageView iv = (ImageView) view;
									iv.setImageBitmap(Utils.toRoundBitmap(loadedImage));
								}
							}

						});

						if(!TextUtils.isEmpty(video.getName())){
							holder.user_name.setText(video.getName());
						}else{
							holder.user_name.setText("");
						}
						if (!TextUtils.isEmpty(video.getDuration())) {
							holder.tv_duration.setText(Utility.getDuration(video
									.getDuration()));
						} else {
							holder.tv_duration.setText("00:00");
						}

					}

					break;
				case 1:
					holder.image2.setLayoutParams(params);
					holder.image2.setVisibility(View.VISIBLE);
					holder.title2.setVisibility(View.VISIBLE);
					if (Constant.VIDEO_TYPE_12.equals(video.getAt())
							|| Constant.VIDEO_TYPE_13.equals(video.getAt())
							|| Constant.VIDEO_TYPE_14.equals(video.getAt())
							|| Constant.VIDEO_TYPE_15.equals(video.getAt())) {
						holder.subtitle2.setVisibility(View.VISIBLE);
						holder.title2.setMaxLines(1);
						if (!TextUtils.isEmpty(video.getSub_title())) {
							holder.subtitle2.setText(video.getSub_title());
						} else {
							holder.subtitle2.setText("");
						}
					} else {
						holder.subtitle2.setVisibility(View.GONE);
						holder.title2.setMaxLines(2);
					}
					if (!TextUtils.isEmpty(video.getTitle())) {
						holder.title2.setText(video.getTitle());
					} else {
						holder.title2.setText("");
					}
					if (!TextUtils.isEmpty(video.getMark())) {
						holder.corner2.setText(video.getMark());
						holder.corner2.setVisibility(View.VISIBLE);
					} else {
						holder.corner2.setVisibility(View.GONE);
					}
					if (!TextUtils.isEmpty(video.getPic())) {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image2,
								Constant.VIDEO_9_16_OPTION_2);
					} else {
						holder.image2
						.setImageResource(R.drawable.common_place_holder_bg_16_10);
					}
					if(!TextUtils.isEmpty(video.getAt()) && video.getAt().equals("11")){
						holder.tv_logo2.setVisibility(View.VISIBLE);
						holder.tv_logo2.setText("秒评");
					}else{
						holder.tv_logo2.setVisibility(View.GONE);
					}

					if(video.getAt().equals("5") || video.getAt().equals("11")){
						holder.rl_user2.setVisibility(View.GONE);
					}else{
						holder.rl_user2.setVisibility(View.VISIBLE);
						holder.iv_headpic2.setVisibility(View.VISIBLE);
						holder.user_name2.setVisibility(View.VISIBLE);
						holder.tv_duration2.setVisibility(View.VISIBLE);

						ImageLoader.getInstance().displayImage(video.getHeadpic(),
								holder.iv_headpic2, Constant.IMAGE_OPTIONS_FOR_USER_OTHER, new SimpleImageLoadingListener() {

							public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
								if(loadedImage!=null){
									ImageView iv = (ImageView) view;
									iv.setImageBitmap(Utils.toRoundBitmap(loadedImage));
								}
							}

						});

						if(!TextUtils.isEmpty(video.getName())){
							holder.user_name2.setText(video.getName());
						}else{
							holder.user_name2.setText("");
						}
						if (!TextUtils.isEmpty(video.getDuration())) {
							holder.tv_duration2.setText(Utility.getDuration(video
									.getDuration()));
						} else {
							holder.tv_duration2.setText("00:00");
						}
					}
					break;
				case 2:
					holder.layRow.setVisibility(View.VISIBLE);
					holder.layitem3.setVisibility(View.VISIBLE);
					holder.layitem4.setVisibility(View.VISIBLE);
					holder.image3.setLayoutParams(params);
					holder.image3.setVisibility(View.VISIBLE);
					holder.title3.setVisibility(View.VISIBLE);
					if (Constant.VIDEO_TYPE_12.equals(video.getAt())
							|| Constant.VIDEO_TYPE_13.equals(video.getAt())
							|| Constant.VIDEO_TYPE_14.equals(video.getAt())
							|| Constant.VIDEO_TYPE_15.equals(video.getAt())) {
						holder.subtitle3.setVisibility(View.VISIBLE);
						holder.title3.setMaxLines(1);
						if (!TextUtils.isEmpty(video.getSub_title())) {
							holder.subtitle3.setText(video.getSub_title());
						} else {
							holder.subtitle3.setText("");
						}
					} else {
						holder.subtitle3.setVisibility(View.GONE);
						holder.title3.setMaxLines(2);
					}
					if (!TextUtils.isEmpty(video.getTitle())) {
						holder.title3.setText(video.getTitle());
					} else {
						holder.title3.setText("");
					}
					if (!TextUtils.isEmpty(video.getMark())) {
						holder.corner3.setText(video.getMark());
						holder.corner3.setVisibility(View.VISIBLE);
					} else {
						holder.corner3.setVisibility(View.GONE);
					}
					if (!TextUtils.isEmpty(video.getPic())) {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image3,
								Constant.VIDEO_9_16_OPTION_2);
					} else {
						holder.image3
						.setImageResource(R.drawable.common_place_holder_bg_16_10);
					}


					if(!TextUtils.isEmpty(video.getAt()) && video.getAt().equals("11")){
						holder.tv_logo3.setVisibility(View.VISIBLE);
						holder.tv_logo3.setText("秒评");
					}else{
						holder.tv_logo3.setVisibility(View.GONE);
					}

					if(video.getAt().equals("5") || video.getAt().equals("11")){
						holder.rl_user3.setVisibility(View.GONE);
					}else{
						holder.rl_user3.setVisibility(View.VISIBLE);
						holder.iv_headpic3.setVisibility(View.VISIBLE);
						holder.user_name3.setVisibility(View.VISIBLE);
						holder.tv_duration3.setVisibility(View.VISIBLE);

						ImageLoader.getInstance().displayImage(video.getHeadpic(),
								holder.iv_headpic3, Constant.IMAGE_OPTIONS_FOR_USER_OTHER, new SimpleImageLoadingListener() {

							public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
								if(loadedImage!=null){
									ImageView iv = (ImageView) view;
									iv.setImageBitmap(Utils.toRoundBitmap(loadedImage));
								}
							}

						});

						if(!TextUtils.isEmpty(video.getName())){
							holder.user_name3.setText(video.getName());
						}else{
							holder.user_name3.setText("");
						}
						if (!TextUtils.isEmpty(video.getDuration())) {
							holder.tv_duration3.setText(Utility.getDuration(video
									.getDuration()));
						} else {
							holder.tv_duration3.setText("00:00");
						}

					}
					break;
				case 3:
					holder.image4.setLayoutParams(params);
					holder.image4.setVisibility(View.VISIBLE);
					holder.title4.setVisibility(View.VISIBLE);
					if (Constant.VIDEO_TYPE_12.equals(video.getAt())
							|| Constant.VIDEO_TYPE_13.equals(video.getAt())
							|| Constant.VIDEO_TYPE_14.equals(video.getAt())
							|| Constant.VIDEO_TYPE_15.equals(video.getAt())) {
						holder.subtitle4.setVisibility(View.VISIBLE);
						holder.title4.setMaxLines(1);
						if (!TextUtils.isEmpty(video.getSub_title())) {
							holder.subtitle4.setText(video.getSub_title());
						} else {
							holder.subtitle4.setText("");
						}
					} else {
						holder.subtitle4.setVisibility(View.GONE);
						holder.title4.setMaxLines(2);
					}
					if (!TextUtils.isEmpty(video.getTitle())) {
						holder.title4.setText(video.getTitle());
					} else {
						holder.title4.setText("");
					}
					if (!TextUtils.isEmpty(video.getMark())) {
						holder.corner4.setText(video.getMark());
						holder.corner4.setVisibility(View.VISIBLE);
					} else {
						holder.corner4.setVisibility(View.GONE);
					}
					if (!TextUtils.isEmpty(video.getPic())) {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image4,
								Constant.VIDEO_9_16_OPTION_2);
					} else {
						holder.image4
						.setImageResource(R.drawable.common_place_holder_bg_16_10);
					}

					if(!TextUtils.isEmpty(video.getAt()) && video.getAt().equals("11")){
						holder.tv_logo4.setVisibility(View.VISIBLE);
						holder.tv_logo4.setText("秒评");
					}else{
						holder.tv_logo4.setVisibility(View.GONE);
					}

					if(video.getAt().equals("5") || video.getAt().equals("11")){
						holder.rl_user4.setVisibility(View.GONE);
					}else{

						holder.rl_user4.setVisibility(View.VISIBLE);
						holder.iv_headpic4.setVisibility(View.VISIBLE);
						holder.user_name4.setVisibility(View.VISIBLE);
						holder.tv_duration4.setVisibility(View.VISIBLE);

						ImageLoader.getInstance().displayImage(video.getHeadpic(),
								holder.iv_headpic4, Constant.IMAGE_OPTIONS_FOR_USER_OTHER, new SimpleImageLoadingListener() {

							public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
								if(loadedImage!=null){
									ImageView iv = (ImageView) view;
									iv.setImageBitmap(Utils.toRoundBitmap(loadedImage));
								}
							}

						});

						if(!TextUtils.isEmpty(video.getName())){
							holder.user_name4.setText(video.getName());
						}else{
							holder.user_name4.setText("");
						}
						if (!TextUtils.isEmpty(video.getDuration())) {
							holder.tv_duration4.setText(Utility.getDuration(video
									.getDuration()));
						} else {
							holder.tv_duration4.setText("00:00");
						}

					}
					break;
				default:
					break;
				}
			}
		} else {
			holder.layitem.setVisibility(View.GONE);
			holder.layitem2.setVisibility(View.GONE);
			holder.layRow.setVisibility(View.GONE);
		}

		if(mAdLstData != null && mAdLstData.size()>position){
			if(mAdLstData.get(position) != null){
				holder.ad_biaoqian.setVisibility(View.VISIBLE);
				holder.view_ad.setVisibility(View.VISIBLE);
				holder.ll_ad.setVisibility(View.GONE);
				holder.view_adline.setVisibility(View.VISIBLE);
				if(mAdLstData.get(position).get(0) != null){
					final RecommendAdInfo recommendAdInfo = mAdLstData.get(position).get(0);

					if(recommendAdInfo.getShowType().equals("0")){
						if(recommendAdInfo.getImageUrl() != null && recommendAdInfo.getImageUrl().size()>0){
							holder.iv_ad.setLayoutParams(param_ad);
							holder.iv_ad.setVisibility(View.VISIBLE);
							holder.ll_ad.setVisibility(View.GONE);
							ImageLoader.getInstance().displayImage(recommendAdInfo.getImageUrl().get(0),
									holder.iv_ad,
									Constant.VIDEO_9_16_OPTION_2);
						}
					}else if(recommendAdInfo.getShowType().equals("1")){
						holder.iv_ad.setVisibility(View.GONE);
						holder.ll_ad.setVisibility(View.VISIBLE);
						holder.iv_ad1.setLayoutParams(params);
						holder.iv_ad2.setLayoutParams(params);
						if(recommendAdInfo.getImageUrl() != null && recommendAdInfo.getImageUrl().size()>1){
							ImageLoader.getInstance().displayImage(recommendAdInfo.getImageUrl().get(0),
									holder.iv_ad1,
									Constant.VIDEO_9_16_OPTION_2);
							ImageLoader.getInstance().displayImage(recommendAdInfo.getImageUrl().get(1),
									holder.iv_ad2,
									Constant.VIDEO_9_16_OPTION_2);
						}
					}
					if(!TextUtils.isEmpty(recommendAdInfo.getTitle())){
						holder.ad_title.setText(recommendAdInfo.getTitle());
					}else{
						holder.ad_title.setText("");
					}

					new NetEngine().AdUpToServer(mContext,
							"11", LoginInfo
							.getInstance().getUserId(), recommendAdInfo.getId(),
							"1", "-1");
					holder.view_ad.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							new NetEngine().AdUpToServer(mContext,
									"11", LoginInfo
									.getInstance().getUserId(), recommendAdInfo.getId(),
									"2", "-1");
							if(recommendAdInfo.getType().equals("5")){
								String ad_url = recommendAdInfo.getAssociation();
								if(!ad_url.contains("http://")){
									ad_url= "http://"+ad_url;
								}
								Uri uri = Uri.parse(ad_url);
								Intent it = new Intent(Intent.ACTION_VIEW, uri);
								mContext.startActivity(it);
								
//								Intent intent = new Intent();
//								intent.setClass(mContext, WebViewActivity3.class);
//								intent.putExtra("adLink", ad_url);
//								intent.putExtra(WebViewActivity3.FLAG_TITLE, recommendAdInfo.getTitle());
//								mContext.startActivity(intent);
							}else{
								TransferUtils.getInstance().transferActivity(mContext,
										recommendAdInfo.getAssociation(), recommendAdInfo.getType(), recommendAdInfo.getTitle(),recommendAdInfo.getAssociation(), recommendAdInfo.getImageUrl().get(0),recommendAdInfo.getAssociation(),
										recommendAdInfo.getAssociation(), Constant.ADV_SOURCE_RECOMMEND,"");
							}
						}
					});
				}

			}else{
				holder.view_ad.setVisibility(View.GONE);
				holder.view_adline.setVisibility(View.GONE);
			}

		}else{
			holder.view_ad.setVisibility(View.GONE);
			holder.view_adline.setVisibility(View.GONE);
		}

		holder.more.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if ("500".equals(info.getCid())) {
					TransferUtils.getInstance().transferMainSecond(mContext);
				} else {
					if (mOnChannelListener != null) {
						mOnChannelListener.onChannelListener(info.getCid(),
								info.getCtype());
					}
				}
			}
		});

		holder.layLink.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getLittetop() != null
						&& info.getLittetop().size() > 0) {
					transferActivity(info.getLittetop().get(0));
				}
			}
		});

		holder.layLink2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getLittetop() != null
						&& info.getLittetop().size() > 1) {
					transferActivity(info.getLittetop().get(1));
				}
			}
		});

		holder.layitem.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getVideolist() != null
						&& info.getVideolist().size() > 0) {
					transferActivity(info.getVideolist().get(0));
				}
			}
		});
		holder.layitem2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getVideolist() != null
						&& info.getVideolist().size() > 1) {
					transferActivity(info.getVideolist().get(1));
				}
			}
		});
		holder.layitem3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getVideolist() != null
						&& info.getVideolist().size() > 2) {
					transferActivity(info.getVideolist().get(2));
				}
			}
		});
		holder.layitem4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (info.getVideolist() != null
						&& info.getVideolist().size() > 3) {
					transferActivity(info.getVideolist().get(3));
				}
			}
		});
		return convertView;
	}

	/**
	 * 跳转页面
	 * 
	 * @param video
	 */
	private void transferActivity(VideoTB video) {
		if (Helper.checkConnection(mContext)) {
			TransferUtils.getInstance().transferActivity(mContext,
					video.getVid(), video.getAt(), video.getTitle(),video.getVideoUrl(), video.getAdURL(), video.getPic(),
					video.getTid(), Constant.ADV_SOURCE_RECOMMEND,video.getName());
		} else {
			Toast.makeText(mContext, R.string.net_no_notclick,
					Toast.LENGTH_SHORT).show();
		}
	}

	private class Holder {
		public TextView name;
		public TextView more;
		public View layLine;
		public View layLink;
		public TextView mark;
		public TextView linktitle;
		public View layLink2;
		public TextView mark2;
		public TextView linktitle2;
		public View layitem;
		public ImageView image;
		public TextView title;
		public TextView subtitle;
		public TextView corner;
		public View layitem2;
		public ImageView image2;
		public TextView title2;
		public TextView subtitle2;
		public TextView corner2;
		public View layRow;
		public View layitem3;
		public ImageView image3;
		public TextView title3;
		public TextView subtitle3;
		public TextView corner3;
		public View layitem4;
		public ImageView image4;
		public TextView title4;
		public TextView subtitle4;
		public TextView corner4;
		public View ll_ad,view_ad;
		public ImageView iv_ad,iv_ad1,iv_ad2,iv_headpic,iv_headpic2,iv_headpic3,iv_headpic4;
		public RelativeLayout rl_user,rl_user2,rl_user3,rl_user4;
		public TextView user_name,user_name2,user_name3,user_name4,tv_duration,tv_duration2,tv_duration3,tv_duration4,ad_biaoqian,ad_title;
		public View view_adline;
		public TextView tv_logo,tv_logo2,tv_logo3,tv_logo4;
	}

}
